package com.haiheng.voiceandbook.adapter

import android.graphics.Bitmap
import android.widget.ImageView
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.BaseViewHolder
import com.haiheng.bookmusic.utils.GlideUtils
import com.haiheng.voiceandbook.Constants
import com.haiheng.voiceandbook.Constants.Companion.BASE_URL
import com.haiheng.voiceandbook.R
import com.haiheng.voiceandbook.common.BookDto
import com.haiheng.voiceandbook.utils.DisplayUtil
import com.haiheng.voiceandbook.utils.ZXingUtils


class BookFindAdapter(layoutResId: Int, data: List<BookDto>?) :
        BaseQuickAdapter<BookDto, BaseViewHolder>(layoutResId, data) {
    private val TAG = "BookFindAdapter"
    override fun convert(helper: BaseViewHolder?, item: BookDto?) {
        helper?.run {
            setText(R.id.tv_name, item?.bookName)
            setText(R.id.tv_author, item?.author)
            setText(R.id.tv_desc, item?.summary)
            val imageView = getView<ImageView>(R.id.iv_image)
            GlideUtils.load(mContext, item!!.coverImg, imageView)
            val iv_qcode = getView<ImageView>(R.id.iv_qcode)

            val url = "${BASE_URL}webview/index.html#/pages/bookPage/bookPage?id=${item.getBookId()}&libraryNo=${Constants.getLibraryCode()}&PhysicalAddress=${Constants.getDevicesId()}"

            val bitmap: Bitmap = ZXingUtils.createQRImage(
                    url,
                    DisplayUtil.dip2px(mContext, 36f),
                    DisplayUtil.dip2px(mContext, 36f)
            )
            iv_qcode.setImageBitmap(bitmap)


        }


    }


}